package com.classichu.jetpacksimple;

import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.classichu.jetpacksimple.adapter.MyFragmentPagerAdapter;
import com.classichu.jetpacksimple.ui.main.MainFragment;
import com.classichu.jetpacksimple.ui.main.douban.DoubanFragment;
import com.classichu.jetpacksimple.ui.main.meizi.MeiziFragment;
import com.classichu.jetpacksimple.ui.main.zhihu.ZhihuFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    viewPager.setCurrentItem(0);
                    return true;
                case R.id.navigation_dashboard:
                    viewPager.setCurrentItem(1);
                    return true;
                case R.id.navigation_notifications:
                    viewPager.setCurrentItem(2);
                    return true;
                case R.id.navigation_notifications2:
                    viewPager.setCurrentItem(3);
                    return true;
            }
            return false;
        }
    };
    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
      /*  if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, MainFragment.newInstance())
                    .commitNow();
        }*/

        viewPager = findViewById(R.id.vp_home);
        BottomNavigationView bottomNavigationView = findViewById(R.id.navigation);
        Toolbar toolbar = findViewById(R.id.tool_bar);

        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(ZhihuFragment.newInstance());
        fragmentList.add(MeiziFragment.newInstance());
        fragmentList.add(DoubanFragment.newInstance());
        fragmentList.add(MainFragment.newInstance());
        MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);
        viewPager.setAdapter(adapter);


        bottomNavigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        toolbar.setTitle("test");
        setSupportActionBar(toolbar);

    }
}
